<?php

namespace BWL\webshopBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;


class EntityController extends Controller
{
  public function showSpecificItemAction($id) {
    $doctrine = $this->getDoctrine();
    $item = $doctrine->getRepository('BWLwebshopBundle:Item')->find($id);
    //get inclosing items
    $inclosingItemsIds = $doctrine->getRepository('BWLwebshopBundle:ItemItem')->findBy(array('whole_item' => $id));
    //
    $inclosingItems = array();
    if($inclosingItemsIds) {
      foreach($inclosingItemsIds as $itemId) {
        $tempArray = array();
        $tempArray['item'] = $itemId->getPartItem();
        $tempArray['mass'] = $itemId->getCount();
        array_push($inclosingItems, $tempArray);

      }
    }

    if(!$item) {
      throw $this->createNotFoundException('No product found.');
    }
    return $this->render('BWLwebshopBundle:Page:showSpecificItem.html.twig', array('item' => $item, 'inclosingItems' => $inclosingItems));
  }
}
